import { Outlet, useLocation } from 'react-router-dom'
import { Sidebar } from './Sidebar'
import { UserApi } from '@/api/user'
import { useUserStore } from '@/store/user'
import { useEffect } from 'react'

export default function Layout() {

  const { setUser } = useUserStore()
  const location = useLocation()

  useEffect(() => {
    console.log(location.pathname)
    UserApi.getProfile().then(res => {
      console.log(res)
      setUser({
        id: res.user.userId,
        username: res.user.username,
        email: res.user.email,
      })
    })
  }, [])

  return (
    <>
      <div className="flex h-screen">
        <Sidebar />
        <main className="flex-1 overflow-auto">
          <Outlet />
        </main>
      </div>
    </>
  )
} 